<?php
class cityStreet extends connect
{
	function __construct($city, $street, $building)
	{
		parent::__construct('cs');
		$checkAddress=new checkAddress();
		$street=$checkAddress->checkStreet($street);
		$building=$checkAddress->checkBuilding($building);
		$condition="WHERE street='$street'";
		$res=parent::select_all($city, $condition);
		if(mysql_num_rows($res)<1)
		{			$data="street='$street', buildings='$building'";
			parent::insert_data($city, $data);
		}
		else
		{			$row=mysql_fetch_array($res);
			$buildings=explode(',', $row['buildings']);
			if(!in_array($building, $buildings))
			{				$buildings[]=$building;
				sort($buildings);
				$buildings=implode(',', $buildings);
				$data="buildings='$buildings'";
				$condition="WHERE street='$street'";
				parent::update_data($city, $data, $condition);
			}
		}
	}
}


